<?php
/**
 * Error Handler Klasse
 *
 * $Rev: $
 * $Author: $
 * $Date: $
 * $Id: $
 * $URL: $
 * @author Adrian Liechti <info@jahweh.ch>
 * @copyright: 2010-2011 Adrian Liechti, GPL3 and CC3 BY-SA
 */

class errorHandler {
	
	protected $lastHandler;

	public function __construct() {
		$this->lastHandler = set_error_handler(array($this, 'handle'));
		register_shutdown_function(array($this, 'fatalError'));
	}

	public function fatalError() {
		$e = error_get_last();
		if($e) $this->handle($e['type'], $e['message'], $e['file'], $e['line']);
	}

	public function handle($code = null, $message = null, $file = null, $line = null) {
		if(!$code) $code = E_USER_ERROR;
		$trace = debug_backtrace();
		$err = new errorHandlerException($message, $code);
		$err->addFileLineTrace($file, $line, $trace);
	}
}

?>